// task_pkg/pages/anomaly/anomaly.js
Page({
  data: {
    radio: 1,
    message: '',
    title: "选择时间",
    popTime: false,
    showType: false,
    minHour: 10,
    maxHour: 20,
    currentDate: new Date(),
    minDate: new Date().getTime(),
    maxDate: new Date(2023, 11, 31).getTime(),
    formatter(type, value) {
      if (type === 'month') {
        return `${value}月`;
      } else if (type === 'day') {
        return `${value}日`;
      } else if (type === 'hour') {
        return `${value}点`;
      } else if (type === 'minute') {
        return `${value}分`;
      }
      return value;
    },

    actions: [
      "发动机启动困难",
      "不着车，漏油",
      "照明失灵",
      "有异常响动",
      "排烟异常、温度异常",
      "其他问题"
    ],
    accidentImagesList: []
  },
  onClickLeft() {
    wx.navigateBack({
      delta: 1
    })
  },
  afterReadOne(e) { //事故照片
    console.log(e);
    console.log(e.detail.file.url);
    const url = e.detail.file.url
    this.setData({
      accidentImagesList: [...this.data.accidentImagesList, url]
    })
    // console.log(this.data.accidentImagesList);
  },
  deleteOne(e) { //删除事故照片
    console.log(e);
    const index = e.detail.index
    const accidentImagesList = this.data.accidentImagesList.splice(index, 1)
    this.setData({
      accidentImagesList
    })
  },
  onChange(event) {
    console.log('----', event);
    this.setData({
      radio: event.detail,
    });
  },
  cancel() { //取消时间按钮
    this.setData({
      popTime: false
    })
  },
  confirm(e) {
    console.log('时间戳', e.detail);
    const timestamp = this.timestamp(e.detail)
    console.log('确认', timestamp);
    this.setData({
      endTime: timestamp
    })
    this.cancel()
  },
  timestamp(timestamp) {
    const date = new Date(timestamp);
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    const hour = String(date.getHours()).padStart(2, '0');
    const minute = String(date.getMinutes()).padStart(2, '0');
    const formattedDate = `${year}.${month}.${day} ${hour}:${minute}`;
    return formattedDate
  },
  submitType() {
    this.onCloseType()
  },
  onClick(event) {
    console.log(event);
    const {
      name
    } = event.currentTarget.dataset
    this.setData({
      radio: name,
    });
  },
  onInput(event) {
    this.setData({
      currentDate: event.detail,
    });
  },
  openShowType() {
    this.setData({
      showType: true
    })
  },
  openShowTime() {
    this.setData({
      popTime: true
    })
  },
  onCloseTime() {
    this.setData({
      showTime: false
    })
  },
  onCloseType() {
    this.setData({
      showType: false
    })
  }
})